package xyz.naokeziteng.leetcode;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @author hawk
 * @date 2022/7/27
 * @desc
 **/
public class MyStack {
    private Queue<Integer> queue;


    public MyStack() {
        queue = new LinkedList<>();
    }

    /*public void push(int x) {
        if (queue.isEmpty()) {
            queue.offer(x);
            return;
        }
        int size = queue.size();
        int[] data = new int[size + 1];
        data[0] = x;
        for (int i = 0; i < size; i++) {
            data[i + 1] = queue.poll();
        }
        for (int i = 0; i < data.length; i++) {
            queue.offer(data[i]);
        }
    }*/

    public void push(int x) {
        int size = queue.size();
        queue.offer(x);
        for (int i = 0; i < size; i++) {
            queue.offer(queue.poll());
        }
    }

    public int pop() {
        return queue.poll();
    }

    public int top() {
        return queue.peek();
    }

    public boolean empty() {
        return queue.isEmpty();
    }

    public static void main(String[] args) {
        MyStack myStack = new MyStack();
        myStack.push(1);
        myStack.push(2);
        myStack.push(3);
        myStack.push(4);
        System.out.println(myStack.pop());
        System.out.println(myStack.pop());
        System.out.println(myStack.pop());
        System.out.println(myStack.pop());
    }
}
